/* Daniel Shiffman               */
/* Programming from A to Z       */
/* Spring 2008                   */
/* http://www.shiffman.net       */
/* daniel.shiffman@nyu.edu       */

/* Demos the various hyponym methods and how they differ (same for hypernyms)
 * Example directly adapted from Daniel Howe's
 * http://www.rednoise.org/rita/examples/VariousHyponyms/VariousHyponyms.pde
 */

package com.irssproject.app;


public class Hyponyms {
/*
	public static void main (String[] args) {
		
		// Start with the word cat as a noun
		String[] clusters = new String[]{"animal"};//, "cat", "dog", "tree", "fly", "level", "sad", "people", "phone", "communications", "cloud", "Internet", "Code", "Game", "Microsoft", "Linux", "Google", "Android", "Browser", "Software"};
		RiWordnet wordnet = new RiWordnet(null);
		String pos = "n";

		
//		for (int i=0;i<clusters.length; i++)
//		{
//			WordNetTree wnt = generateWordNetTree(clusters[i], pos, wordnet);
//			//Let's iterate over the rest of clusters, creating their tree and comparing with the present cluster
//			
//			WordNetTree wntAux = new WordNetTree();
//			for (int j=i+1;j<clusters.length;j++)
//			{
//				wntAux = generateWordNetTree(clusters[j], pos, wordnet);
//				
//				
//				
//				
//				
//			}
//			
//		}
//		
	//	WordNetTree wnt = generateWordNetTree("sport", pos, wordnet);

		float dist1 = wordnet.getDistance("sport", "wrestling", pos);
		float dist2 = wordnet.getDistance("sport", "softball", pos);

		String[] similars = wordnet.getAllCoordinates("football", "n");
		
		String[] parents = wordnet.getCommonParents(similars[3], similars[6], pos);
		float dist3 = wordnet.getDistance("sport", "rugby", pos);

		String[] stems = wordnet.getStems("animal", pos);
		
		for (int i=0;i<stems.length;i++)
			System.out.println(stems[i]);
	
		System.out.println("********** similars **********");
		for (int i=0;i<similars.length;i++)
			System.out.println(similars[i]);

		System.out.println("dist1: "+dist1+", dist2: "+dist2+", dist3: "+dist3);

	}
	
	public static WordNetTree generateWordNetTree(String presentWord, String pos, RiWordnet wordnet)
	{
		// First we can look at all of the senses
		int[] ids = new int[]{};

		// An array for any results we get


		ids = wordnet.getSenseIds(presentWord, pos);
		
		//Two dimensions, first for the diferent synsets, second for the words of each one
		String[][] hypernymsPresentWord=new String[ids.length][];
		String[][] hyponymsPresentWord=new String[ids.length][];


		// Second, we get the hypernyms tree of the word
		System.out.println("\n\n======== get Hypernym tree of the word "+presentWord+" ======");
		for (int j=0;j<ids.length;j++) {
			try {
				hypernymsPresentWord[j] = wordnet.getHypernymTree(ids[j]);
				if (hypernymsPresentWord == null) continue;
			} catch (JWNLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		for (int k=0;k<hypernymsPresentWord.length;k++) {
			System.out.println("#"+ids[k]+":");
			for (int l=0;l<hypernymsPresentWord[k].length;l++)
			{
				System.out.print(hypernymsPresentWord[k][l] + ", ");    
			}
		}

		
		// Third, we get the Hyponyms tree of the word
		System.out.println("\n\n======== get Hyponyms tree of the word "+presentWord+" ======");
		for (int j=0;j<ids.length;j++) {
			hyponymsPresentWord[j] = wordnet.getHyponymTree(ids[j]);
			if (hyponymsPresentWord == null) continue;
		}
		for (int k=0;k<hyponymsPresentWord.length;k++) {
			System.out.println("#"+ids[k]+":");
			for (int l=0;l<hyponymsPresentWord[k].length;l++)
			{
				System.out.print(hyponymsPresentWord[k][l] + ", ");    
			}
		}
		
		WordNetTree wnt = new WordNetTree();
		wnt.setHypernymsList(hypernymsPresentWord);
		wnt.setHyponymsList(hyponymsPresentWord);
		wnt.setBaseWord(presentWord);
		
		return wnt;


		
	}
	
	public static void compareWordNetTrees(WordNetTree wnt1, WordNetTree wnt2)
	{
		
		String wordWnt1 = wnt1.getBaseWord();
		String wordWnt2 = wnt2.getBaseWord();
		String[][] hypernymsWnt1=wnt1.getHypernymsList();
		String[][] hyponymsWnt1=wnt1.getHyponymsList();
		String[][] hypernymsWnt2=wnt2.getHypernymsList();
		String[][] hyponymsWnt2=wnt2.getHyponymsList();
		
		for (int i=0;i<hypernymsWnt2.length;i++)
		{
			if (wordWnt1.equals(hypernymsWnt2[i]))
			{
				//MATCH!!! wordWnt1 is an Hypernym of wordWnt2 at distance "i"!
				
			}
		}
		
	}

	*/
}
